<%@ page import="com.feng.ALittleFlower.Database" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    if (session.getAttribute("username") == null) {
        response.sendRedirect("./notavailable.jsp");
    }
    request.setCharacterEncoding("utf-8");
    String rate = request.getParameter("rate");
    String comment = request.getParameter("comment");
    String username = (String) session.getAttribute("username");
    if (rate != null && comment != null) {
        int rating = Integer.parseInt(rate);
        try {
            Database.addComment(username, rating, comment);
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect("./read.jsp");
    }
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link href="./css/bootstrap.css" rel="stylesheet">
    <link href="read.css" rel="stylesheet">
    <title>发布影评</title>
</head>

<body class="bg d-flex">
<%@include file="navbar.jsp" %>
<div class="container my-5 py-5">
    <div class="row">
        <div class="col-12 text-end">
            <div class="col-12 ">
                <a href="read.jsp"><button class="btn btn-lg btn-outline-primary">观看影评</button></a>
                <button class="btn btn-lg btn-primary disabled" disabled>发布影评</button>
                <hr class="mx-auto">
            </div>
        </div>
    </div>
    <form class="form_container" method="post" oninput="showRate.value=parseInt(rate.value)">
        <label for="rate" class="h3 form-label" required>评分:  </label>
        <output name="showRate" for="rate" class="h3"></output>
        <input type="range" name="rate" class="form-range" id="rate" value="5" min="1" max="10">
        <hr class="w-100 mx-auto">
        <div class="my-3 form-floating">
            <textarea class="form-control" placeholder="写下你的影评吧" id="comment" name="comment" required style="min-height: 300px"></textarea>
            <label for="comment">写下你的影评吧</label>
        </div>

        <button type="submit" class="btn btn-primary btn-lg">发布</button>
    </form>
</div>



<script src="js/popper.js"></script>
<script src="js/bootstrap.js"></script>
</body>

</html>